package com.fpx.order.plat.bussiness.plat.amazon.task;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fpx.order.plat.bussiness.dao.log.IPullOrderLogDao;
import com.fpx.order.plat.bussiness.entity.CustomerShop;
import com.fpx.order.plat.bussiness.plat.amazon.service.AmazonDeliveryOrderHandler;
import com.fpx.order.plat.bussiness.plat.base.PlatOrderCurrentJob;
import com.fpx.order.plat.bussiness.system.PlatConstants;

@Component
public class AmazonDeliveryOrderJob extends PlatOrderCurrentJob{

	private final static Logger LOGGER = Logger.getLogger(AmazonDeliveryOrderJob.class);
	
	@Autowired
	private AmazonDeliveryOrderHandler amazonDeliveryOrderHandler;
	
	@Autowired
	private IPullOrderLogDao pullOrderLogDao;
	/**
	 * 定时任务
	 */
	public void exec(){
		LOGGER.info("【亚马逊amazon】 自动同步平台订单开始.....");
		initMeodth(PlatConstants.ORDER_SOURCE_AM);
		int reqNum=0;
		List<CustomerShop> customerLst=super.getCustomers();
			if(!org.springframework.util.StringUtils.isEmpty(customerLst)){
				// 遍历商家和店铺
		        for (CustomerShop customer : customerLst) {
		        	String cm_id=customer.getCm_id();
					String cs_id=customer.getCs_id();//商铺ID
		            try {
//		            	if("531221".equals(cm_id)&&"242".equals(cs_id)){
		            		amazonDeliveryOrderHandler.deliveryOrder(customer,reqNum);
//		            	}
		            } catch (Exception ex) {
				        LOGGER.error("【AMAZON】---商家:["+cm_id+"]-商铺ID:["+cs_id+"]-【异常信息】: "+ex.getMessage());
		         }
		      } 
		 }
       LOGGER.info("【亚马逊amazon】  自动同步平台订单结束");
	}
}
